<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="产品名称/顾客" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['customer', validatorRules.customer]" placeholder="请输入产品名称/顾客"></a-input>
        </a-form-item>
        <a-form-item label="状态号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['statusNum', validatorRules.statusNum]" placeholder="请输入状态号"></a-input>
        </a-form-item>
        <a-form-item label="数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['num', validatorRules.num]" placeholder="请输入数量" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="分类（首件、巡检、末件）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['type', validatorRules.type]" :trigger-change="true" dictCode="zs_inspect_type" placeholder="请选择分类（首件、巡检、末件）"/>
        </a-form-item>
        <a-form-item label="物料确认-PCB板" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['project01', validatorRules.project01]" :trigger-change="true" dictCode="zs_inspect_confirm" placeholder="请选择物料确认-PCB板"/>
        </a-form-item>
        <a-form-item label="物料确认-物料" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['project02', validatorRules.project02]" :trigger-change="true" dictCode="zs_inspect_confirm" placeholder="请选择物料确认-物料"/>
        </a-form-item>
        <a-form-item label="物料确认-BOM表" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['project03', validatorRules.project03]" :trigger-change="true" dictCode="zs_inspect_confirm" placeholder="请选择物料确认-BOM表"/>
        </a-form-item>
        <a-form-item label="功能确认-焊接效果" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['project04', validatorRules.project04]" :trigger-change="true" dictCode="zs_inspect_confirm" placeholder="请选择功能确认-焊接效果"/>
        </a-form-item>
        <a-form-item label="功能确认-程序烧写" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['project05', validatorRules.project05]" :trigger-change="true" dictCode="zs_inspect_confirm" placeholder="请选择功能确认-程序烧写"/>
        </a-form-item>
        <a-form-item label="功能确认-功能检测" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['project06', validatorRules.project06]" :trigger-change="true" dictCode="zs_inspect_confirm" placeholder="请选择功能确认-功能检测"/>
        </a-form-item>
        <a-form-item label="功能确认-耐压绝缘" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['project07', validatorRules.project07]" :trigger-change="true" dictCode="zs_inspect_confirm" placeholder="请选择功能确认-耐压绝缘"/>
        </a-form-item>
        <a-form-item label="功能确认-限流值" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['project08', validatorRules.project08]" :trigger-change="true" dictCode="zs_inspect_confirm" placeholder="请选择功能确认-限流值"/>
        </a-form-item>
        <a-form-item label="功能确认-欠压值" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['project09', validatorRules.project09]" :trigger-change="true" dictCode="zs_inspect_confirm" placeholder="请选择功能确认-欠压值"/>
        </a-form-item>
        <a-form-item label="外观确认-外观尺寸" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['project10', validatorRules.project10]" :trigger-change="true" dictCode="zs_inspect_confirm" placeholder="请选择外观确认-外观尺寸"/>
        </a-form-item>
        <a-form-item label="外观确认-线束" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['project11', validatorRules.project11]" :trigger-change="true" dictCode="zs_inspect_confirm" placeholder="请选择外观确认-线束"/>
        </a-form-item>
        <a-form-item label="外观确认-密封效果" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['project12', validatorRules.project12]" :trigger-change="true" dictCode="zs_inspect_confirm" placeholder="请选择外观确认-密封效果"/>
        </a-form-item>
        <a-form-item label="外观确认-铭牌" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['project13', validatorRules.project13]" :trigger-change="true" dictCode="zs_inspect_confirm" placeholder="请选择外观确认-铭牌"/>
        </a-form-item>
        <a-form-item label="外观确认-刻字" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['project14', validatorRules.project14]" :trigger-change="true" dictCode="zs_inspect_confirm" placeholder="请选择外观确认-刻字"/>
        </a-form-item>
        <a-form-item label="外观确认-包装" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['project15', validatorRules.project15]" :trigger-change="true" dictCode="zs_inspect_confirm" placeholder="请选择外观确认-包装"/>
        </a-form-item>
        <a-form-item label="判定（OK/NG）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['decide', validatorRules.decide]" :trigger-change="true" dictCode="zs_inspect_decide" placeholder="请选择判定（OK/NG）"/>
        </a-form-item>
        <a-form-item label="其它（请注明）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['remarks']" rows="4" placeholder="请输入其它（请注明）"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"


  export default {
    name: "ZsFirstPatrolRecordModal",
    components: { 
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          customer: {
            rules: [
              { required: true, message: '请输入产品名称/顾客!'},
            ]
          },
          statusNum: {
            rules: [
              { required: true, message: '请输入状态号!'},
            ]
          },
          num: {
            rules: [
              { required: true, message: '请输入数量!'},
            ]
          },
          type: {
            rules: [
              { required: true, message: '请输入分类（首件、巡检、末件）!'},
            ]
          },
          project01: {
            rules: [
              { required: true, message: '请输入物料确认-PCB板!'},
            ]
          },
          project02: {
            rules: [
              { required: true, message: '请输入物料确认-物料!'},
            ]
          },
          project03: {
            rules: [
              { required: true, message: '请输入物料确认-BOM表!'},
            ]
          },
          project04: {
            rules: [
              { required: true, message: '请输入功能确认-焊接效果!'},
            ]
          },
          project05: {
            rules: [
              { required: true, message: '请输入功能确认-程序烧写!'},
            ]
          },
          project06: {
            rules: [
              { required: true, message: '请输入功能确认-功能检测!'},
            ]
          },
          project07: {
            rules: [
              { required: true, message: '请输入功能确认-耐压绝缘!'},
            ]
          },
          project08: {
            rules: [
              { required: true, message: '请输入功能确认-限流值!'},
            ]
          },
          project09: {
            rules: [
              { required: true, message: '请输入功能确认-欠压值!'},
            ]
          },
          project10: {
            rules: [
              { required: true, message: '请输入外观确认-外观尺寸!'},
            ]
          },
          project11: {
            rules: [
              { required: true, message: '请输入外观确认-线束!'},
            ]
          },
          project12: {
            rules: [
              { required: true, message: '请输入外观确认-密封效果!'},
            ]
          },
          project13: {
            rules: [
              { required: true, message: '请输入外观确认-铭牌!'},
            ]
          },
          project14: {
            rules: [
              { required: true, message: '请输入外观确认-刻字!'},
            ]
          },
          project15: {
            rules: [
              { required: true, message: '请输入外观确认-包装!'},
            ]
          },
          decide: {
            rules: [
              { required: true, message: '请输入判定（OK/NG）!'},
            ]
          },
        },
        url: {
          add: "/inspect/zsFirstPatrolRecord/add",
          edit: "/inspect/zsFirstPatrolRecord/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createTime','customer','statusNum','num','type','project01','project02','project03','project04','project05','project06','project07','project08','project09','project10','project11','project12','project13','project14','project15','decide','remarks'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createTime','customer','statusNum','num','type','project01','project02','project03','project04','project05','project06','project07','project08','project09','project10','project11','project12','project13','project14','project15','decide','remarks'))
      },

      
    }
  }
</script>